package Second;

public class Application {
	String name;
	String password;
	int num;
	User users[]=new User[num];

	public Application(int num, User[] users) {
		this.num = num;
		this.users = users;
	}
	String title_login() {
		return "******login******";
	}
	String title_registe() {
		return "******registe******";
	}
	
	boolean checkuser(String name) {
		for(int i=0;i<num;i++) {
			if(users[i].getName().equals(name)) {
				return true;
			}
		}
		return false;
	}
	void login(String name,String password) {
		System.out.println(title_login());
		for(int i=0;i<num;i++) {
			if(users[i].getName().equals(name)) {
				if(password.equals(users[i].getpassword())) {
					System.out.println(name+",login success!");
					return;
				}
				else {
					System.out.println(name+",login fail!");
					return;
				}
			}
		}
		System.out.println(name+",login fail!");
		return;
	}
	void registe(String name,String password1,String password2) {
		System.out.println(title_registe());
		if(!password1.equals(password2)) {
			 System.out.println("passwords not equal!");
			 return;
		}
		for(int i=0;i<num;i++) {
			if(users[i].getName().equals(name)) {
				System.out.println(name+",registe fail!");
				return;
			}
		}
		users[num++]=new User(name,password1);
		System.out.println(name+",registe success!");
	}
	
	
	
}
